package com.bs.auth.config;

import com.bs.auth.interceptor.AuthRestInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.ArrayList;
import java.util.Collections;


/**
 * @author bingshao
 * @date 2022/9/21
 **/
@Configuration("authWebConfig")
public class WebConfiguration implements WebMvcConfigurer {

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(getAuthRestInterceptor()).excludePathPatterns(getExcludePathPatterns());
    }

    @Bean
    AuthRestInterceptor getAuthRestInterceptor() {
        return new AuthRestInterceptor();
    }

    /**
     * 需要放行的url
     *
     * @return 需要放行的url
     */
    private ArrayList<String> getExcludePathPatterns() {
        ArrayList<String> list = new ArrayList<>();
        String[] urls = {
                "/oauth/**"
        };
        Collections.addAll(list, urls);
        return list;
    }


}
